<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>权限分配</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="Author" content="larry" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="/static/admin/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/common/css/animate.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/admin.css" media="all">
    <style>
        .layui-unselect .layui-form-checkbox .layui-form-checked{
            margin:10px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="larry-container larryms-admin">
        <div class="layui-row layui-col-space20">
            <div class="layui-col-xs12 animated fadeInRightBig">
                <section class="larry-panel">
                    <div class="larryms-page-header">
                        <span class="tit">权限分配</span>
                    </div>
                    <div class="larryms-page-body">
                        <p>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width:40px;">角色名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" id="title" required lay-verify="required" value="{$roleinfo.title}" disabled class="layui-input">
                                </div>
                            </div>
                        </p>
                        <form class="layui-form">
                            <div class="layui-collapse">
                            {volist name="nodes" id="vo" }
                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title"><input type="checkbox" name="ids[]" value="{$vo.id}" title="{$vo.title}" lay-skin="primary" {$vo.checked}></h2>
	                                 {notempty name="vo['child']"}
	                                 {volist name="vo['child']" id="v" }
	                                 <div class="child_1">
	                                    <div class="layui-colla-content layui-show">
	                                       <input type="checkbox" name="ids[]" value="{$v.id}" title="{$v.title}" {$v.checked}>
	                                    </div>
	                                    {notempty name="v['child']"}
	                                    {volist name="v['child']" id="vv" }
	                                     <div class="child_2">
		                                    <div class="layui-colla-content layui-show" style="padding-left:80px;">
		                                        <input type="checkbox" name="ids[]" value="{$vv.id}" title="{$vv.title}" {$vv.checked}>
		                                    </div>
		                                    {notempty name="vv['child']"}
			                           		 {volist name="vv['child']" id="vvv" }
			                           		 <div class="child_3">
					                             <div class="layui-colla-content layui-show" style="padding-left:160px;">
			                                        <input type="checkbox" name="ids[]" value="{$vvv.id}" title="{$vvv.title}" {$vvv.checked}>
			                                    </div>
			                                </div>
	                                    	{/volist}
	                                    	{/notempty}
	                                    </div>
	                                    {/volist}
	                                    {/notempty}
	                                </div>
	                                {/volist}
	                                {/notempty}
                                </div>
							{/volist}
                            </div>
                        </form>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
<!-- 加载js文件-->
<script type="text/javascript" src="/static/admin/common/layui/layui.js"></script>
</body>
<script>
    //Demo
    layui.use(['jquery', 'form', 'layer',], function(){
        var form = layui.form;
        var $ = layui.$;
        var roleid = "{$roleinfo.id}";
        $(".layui-colla-title > div").click(function(){
        	var input  = $(this).prev('input');
        	var status = input.attr('checked');
			if(status){
				input.attr('checked', false);
				$(this).parents('.layui-colla-item').find('input').each(function(){
					$(this).attr('checked', false);
					$(this).next('div').removeClass('layui-form-checked');
				})
			} else {
				input.attr('checked', true);
				$(this).parents('.layui-colla-item').find('input').each(function(){
					$(this).attr('checked', true);
					$(this).next('div').addClass('layui-form-checked');
				})
			}
			submitForm();
        })
        $(".layui-colla-content > div").click(function(){
        	var parent	=	$(this).parent('div');
        	var input  	=	parent.find('input');
        	var status 	=	input.attr('checked');
        	var next   	=	parent.next('div');
        	var last	=	next.next('div');
        	if(status){
        		input.attr('checked', false);
        		parent.next('div').find('input').each(function(){
        			$(this).attr('checked', false).next('div').removeClass('layui-form-checked');
        		})

        	} else {
        		input.attr('checked', true);
        		parent.next('div').find('input').each(function(){
        			$(this).attr('checked', false).next('div').addClass('layui-form-checked');
        		})
        	}
        	sortNodes(this);submitForm();
        })
        function sortNodes(obj){
        	var status = $(obj).parents('.layui-colla-item').find('input:checked').length;
        	if(status){
        		$(obj).parents('.layui-colla-item').find('.layui-colla-title').find('input').attr('checked', true).next('div').addClass('layui-form-checked');
        	} else {
        		$(obj).parents('.layui-colla-item').find('.layui-colla-title').find('input').attr('checked', false).next('div').removeClass('layui-form-checked');
        	}
        	status = $(obj).parents('.child_1').find('input:checked').length;
        	if(status){
        		$(obj).parents('.child_1').find('.layui-colla-content:eq(0)').find('input').attr('checked', true).next('div').addClass('layui-form-checked');
        	} else {
        		$(obj).parents('.child_1').find('.layui-colla-content:eq(0)').find('input').attr('checked', false).next('div').removeClass('layui-form-checked');
        	}
        	status = $(obj).parents('.child_2').find('input:checked').length;
        	if(status){
        		$(obj).parents('.child_2').find('.layui-colla-content:eq(0)').find('input').attr('checked', true).next('div').addClass('layui-form-checked');
        	} else {
        		$(obj).parents('.child_2').find('.layui-colla-content:eq(0)').find('input').attr('checked', false).next('div').removeClass('layui-form-checked');
        	}
        	status = $(obj).parents('.child_3').find('input:checked').length;
        	if(status){
        		$(obj).parents('.child_3').find('.layui-colla-content:eq(0)').find('input').attr('checked', true).next('div').addClass('layui-form-checked');
        	} else {
        		$(obj).parents('.child_3').find('.layui-colla-content:eq(0)').find('input').attr('checked', false).next('div').removeClass('layui-form-checked');
        	}
        	
        }
        
        function submitForm(){
        	var ids = '';
        	$('.layui-form').find('input:checked').each(function(){
        		ids += $(this).val() + ',';
        	})
        	if(ids != ''){
                $.ajax({
                    type:"POST",
                    url:"{:url('admin/Role/updateRoleGroup')}",
                    dataType:"JSON",
                    data:{'ids':ids,'roleid':roleid},
                    success:function(res){
                        if(res.code == '1'){
                        	//console.log(data.code);
                            layer.msg(res.msg, {icon: 6});
                            
                        }else{
                            layer.msg(res.msg, {icon: 5});
                        }
                    }
                });
        	}
        }
    });
</script>

</html>